﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.DistributedServices.Core.ErrorHandlers;
using System.ServiceModel;
using Cesave.Domain.PermisosModule.Contracts.RiegoFuentes;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members

		/// <summary>
		/// 
		/// </summary>
		/// <param name="riegoFuente"></param>
		public void AddRiegoFuente(Domain.PermisosModule.Entities.RiegoFuente riegoFuente)
		{
			try
			{
				IRiegoFuenteService riegoFuenteService = IoCFactory.Resolve<IRiegoFuenteService>();
				riegoFuenteService.AddRiegoFuente(riegoFuente);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="riegoFuente"></param>
		public void ChangeRiegoFuente(Domain.PermisosModule.Entities.RiegoFuente riegoFuente)
		{
			try
			{
				IRiegoFuenteService riegoFuenteService = IoCFactory.Resolve<IRiegoFuenteService>();
				riegoFuenteService.ChangeRiegoFuente(riegoFuente);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.RiegoFuente> FindAllRiegoFuentes()
		{
			try
			{
				IRiegoFuenteService riegoFuenteService = IoCFactory.Resolve<IRiegoFuenteService>();
				return riegoFuenteService.FindAllRiegoFuentes();
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="status"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.RiegoFuente> FindRiegoFuentesByStatus(bool status = true)
		{
			try
			{
				IRiegoFuenteService riegoFuenteService = IoCFactory.Resolve<IRiegoFuenteService>();
				return riegoFuenteService.FindRiegoFuentesByStatus(status);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		#endregion
	}
}